package br.com.nooclix.ptt.ws.adapter;

import java.util.List;

import br.com.nooclix.ptt.core.domain.PttEntity;
import br.com.nooclix.ptt.core.infrastructure.util.ResponseData;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public abstract class AbstractAdapter<E extends PttEntity<Integer>> implements Adapter<E> {
	
	private Gson jsonEngine;
	private Class<E> clazz; 
	
	public AbstractAdapter(Class<E> clazz) {
		super();
		jsonEngine = new GsonBuilder().setDateFormat("dd/MM/yyyy").create();
		this.clazz = clazz;
		
	}

	@Override
	public String convert(E object) {
		return jsonEngine.toJson(object);
	}

	@Override
	public E convert(String json) {
		return jsonEngine.fromJson(json, clazz);
	}

	@Override
	public String convert(ResponseData<E> json) {
		return getJsonEngine().toJson(json);
	}
	
	protected Gson getJsonEngine() {
		return jsonEngine;
	}

	@Override
	public String convert(List<E> list) {
		return jsonEngine.toJson(list);
	}
	
	

}
